/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__fr_queue_node_mk.c                              */
/*  NOTE      =                                                    */
/*  DATE      = 2014/12/17 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "frcomm.h"
#include "frlog.h"
#include "frmem.h"
#include "frlist.h"
#include "frsutl.h"
#include "frhash2.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frct_mng.h"
#include "apmtest_cunit.h"

static int __suite_init(void)
{
	return 0;
}

static int __suite_cleanup(void)
{
	return 0;
}

Frlist_node *__fr_queue_node_mk(int i_direction
                                , u_int ui_src, u_short us_sport
                                , u_int ui_dest, u_short us_dport
                                , Franalyz_cmd em_analyz_cmd
                                , char *p_data, unsigned int ui_data_len
                                , int i_l7_proto
                                , struct timeval st_timeval_pkg);


static void case1(void)
{
    Frlist_node *p_st_node = NULL;
    int i_direction = FR_DIRECT_SRV2CLIENT;
    u_int ui_src = iptools_parse_ipaddr("192.168.1.1");
    u_short us_sport = 80;
    u_int ui_dest = iptools_parse_ipaddr("192.168.0.1");
    u_short us_dport = 22;
    Franalyz_cmd em_analyz_cmd = FRANALYZ_CMD_SYN;
    char *p_data = NULL;
    unsigned int ui_data_len = 4;
    int i_l7_proto = 1;
    struct timeval st_timeval_pkg;
    Apm_packet *p_st_cap_data = NULL;

    st_timeval_pkg.tv_sec = 500;
    st_timeval_pkg.tv_usec = 50;

    p_data = (char *)frmalloc(ui_data_len + 1);
    snprintf(p_data,ui_data_len + 1,"%s","test");

    p_st_node = __fr_queue_node_mk(i_direction,ui_src, us_sport, ui_dest, us_dport
                                   , em_analyz_cmd, p_data, ui_data_len
                                   , i_l7_proto, st_timeval_pkg);

    p_st_cap_data = (Apm_packet *)p_st_node->data;

    CU_ASSERT_EQUAL(p_st_cap_data->src_ip,iptools_parse_ipaddr("192.168.1.1"));
    CU_ASSERT_EQUAL(p_st_cap_data->dst_ip,iptools_parse_ipaddr("192.168.0.1"));
    CU_ASSERT_EQUAL(p_st_cap_data->i_direction,FR_DIRECT_SRV2CLIENT);
    CU_ASSERT_EQUAL(p_st_cap_data->src_port,80);
    CU_ASSERT_EQUAL(p_st_cap_data->dst_port,22);
    CU_ASSERT_EQUAL(p_st_cap_data->ui_payload_len,4);
    CU_ASSERT_EQUAL(p_st_cap_data->st_timestamp.tv_sec,500);
    CU_ASSERT_EQUAL(p_st_cap_data->st_timestamp.tv_usec,50);
    CU_ASSERT_EQUAL(p_st_cap_data->i_l7_proto,1);
    CU_ASSERT_EQUAL(p_st_cap_data->em_analyz_cmd,FRANALYZ_CMD_SYN);
    CU_ASSERT_STRING_EQUAL(p_st_cap_data->p_payload,"test");

    frcap_node_free(p_st_node);
    frfree(p_st_node);
    frfree(p_data);
}



int add_suite()
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("t__fr_queue_node_mk 测试", __suite_init, __suite_cleanup);

	if (NULL == pSuite)
	{
		return 1;
	}


    //增加测试用例
   	CU_add_test(pSuite, "case1", case1);

    return 0;

}

int main(int argc, char **argv)
{
    fr_slab_init(52428800, "test");
    run_cunit(add_suite);
    fr_slab_destroy();

    return 0;
}